/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.crystalrange.documents.service.impl;

import com.googlecode.genericdao.search.Search;
import com.googlecode.genericdao.search.SearchResult;
import java.util.Date;
import java.util.List;
import org.crystalrange.documents.dao.DocumentDao;
import org.crystalrange.documents.model.Document;
import org.crystalrange.documents.service.DocumentService;
import org.crystalrange.model.User;
import org.crystalrange.service.UserService;

/**
 *
 * @author Krzysiek
 */
public class DocumentServiceImpl implements DocumentService {
    
    private DocumentDao documentDao;
    private UserService userService;

    public DocumentDao getDocumentDao() {
        return documentDao;
    }

    public void setDocumentDao(DocumentDao documentDao) {
        this.documentDao = documentDao;
    }

    public UserService getUserService() {
        return userService;
    }

    public void setUserService(UserService userService) {
        this.userService = userService;
    }
    
    public Document create(String username) {
        User currentUser = this.userService.findByUsername(username);   
        
        Document document = new Document();
        document.setCreatedBy(currentUser);
        document.setCreatedDate(new Date());
        
        return document;
    }

    public boolean save(Document document) {
        return this.documentDao.save(document);
    }

    public boolean remove(Document document) {
        return this.documentDao.remove(document);
    }

    public Document find(Long id) {
        return this.documentDao.find(id);
    }

    public List<Document> findAll() {
        return this.documentDao.findAll();
    }

    public SearchResult<Document> searchAndCount(Search search) {
        return this.documentDao.searchAndCount(search);
    }

    public List<Document> search(Search search) {
        return this.documentDao.search(search);
    }

    public Document searchUnique(Search search) {
        return this.documentDao.searchUnique(search);
    }
    
}
